package com.example.campuslink.commen.db

import androidx.room.TypeConverter
import com.example.campuslink.commen.db.comment.CommentTable
import com.example.campuslink.commen.db.invitation.InvitationTable
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

class ListCommentTableConverters {
    private val gson = Gson()
    private val listType = object : TypeToken<MutableList<CommentTable>>() {}.type

    @TypeConverter
    fun fromString(value: String): MutableList<CommentTable>? {
        return if (value.isBlank()) null else gson.fromJson(value, listType)
    }

    @TypeConverter
    fun fromList(list: MutableList<CommentTable>?): String {
        return gson.toJson(list ?: emptyList<CommentTable>())
    }
//    @TypeConverter
//    fun fromCommentList(comments: List<CommentTable>?): String {
//        return Gson().toJson(comments ?: listOf<CommentTable>())
//    }
//
//    @TypeConverter
//    fun toCommentList(json: String?): List<CommentTable> {
//        return if (json.isNullOrEmpty()) emptyList()
//        else Gson().fromJson(json, object : TypeToken<List<CommentTable>>() {}.type)
//    }
}